package com.truongnha.clienttn.data.dao;

import java.util.ArrayList;
import java.util.List;

import com.truongnha.clienttn.business.model.AttendModel;
import com.truongnha.clienttn.data.entity.AttendEntity;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ClassStudentDAO {
	private final SQLiteDatabase db;

	public ClassStudentDAO(SQLiteDatabase db) {
		super();
		this.db = db;
	}

	public long insert(int classId, int studentId) {
		ContentValues inititalValue = new ContentValues();
		inititalValue.put(ClassStudentScheme.CLASS_ID, classId);
		inititalValue.put(ClassStudentScheme.STUDENT_ID, studentId);
		return db.insert(ClassStudentScheme.TABLE_NAME, null, inititalValue);
	}

	public void delete() {
		db.delete(ClassStudentScheme.TABLE_NAME, null, null);
	}

	public List<AttendEntity> getAll() {
		Log.d("LOG", "step 3.3.1");
		String sql = "SELECT * from " + AttendScheme.TABLE_NAME;
		Cursor mcursor = db.rawQuery(sql, null);
		// AccountEntity = accountEntity()
		Log.d("LOG", "step 3.3.2");
		Log.d("LOG", mcursor.toString());

		mcursor.moveToFirst();

		List<AttendEntity> list = new ArrayList<AttendEntity>();
		while (!mcursor.isAfterLast()) {
			AttendEntity attendEntity = new AttendEntity(mcursor.getInt(0),
					mcursor.getString(1), mcursor.getString(2),
					mcursor.getString(3));
			list.add(attendEntity);
			mcursor.moveToNext();
		}
		mcursor.close();
		return list;
	}

}
